
/**		
 * 
 *	uk.co.lmfm.net.subversion.SVNRequest
 *	
 *	@version 1.00 | Jan 11, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.net.subversion 
{
	import org.httpclient.HttpRequest;

	import flash.utils.ByteArray;

	/**
	 * SVNRequest
	 */
	public class SVNRequest extends HttpRequest 
	{
		//	----------------------------------------------------------------
		//	CONSTANTS
		//	----------------------------------------------------------------

		public static const TYPE_PROPFIND : String = 'PROPFIND';
		public static const TYPE_REPORT : String = 'REPORT';

		//	----------------------------------------------------------------
		//	PRIVATE MEMBERS
		//	----------------------------------------------------------------

		private var _type : String;

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function SVNRequest(__type : String = 'REPORT', __depth : int = 1, __body : String = null) 
		{
			super(_type = __type);
			if(_type == TYPE_PROPFIND) addHeader("Depth", __depth.toString());
			body = __body;
		}

		//	----------------------------------------------------------------
		//	PUBLIC ACCESSORS
		//	----------------------------------------------------------------

		override public function set body(value : *) : void
		{
			var bytes : ByteArray = super._body = new ByteArray();
		
			if(value) bytes.writeUTFBytes(String(value));
			bytes.position = 0;
			
			super._header.replace("Content-Type", "text/xml; charset=\"utf-8\"");
			super._header.replace("Content-Length", bytes.length.toString());
		}

		override protected function loadDefaultHeaders() : void 
		{
		// override
		}

		override public function get hasRequestBody() : Boolean 
		{
			return _type == TYPE_REPORT;
		}

		override public function get hasResponseBody() : Boolean 
		{
			return true;
		}
	}
}
